package com.zyj.myapplication.Adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.zyj.myapplication.Activity.ClubInfoActivity;
import com.zyj.myapplication.Javabean.Club;
import com.zyj.myapplication.Model.Constant;
import com.zyj.myapplication.R;

import java.util.List;

import it.sephiroth.android.library.picasso.Picasso;


/**
 * Created by Administrator on 2017/9/26.
 */

public class ClubListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private Context mContext;
    private List mDataList;
    private LayoutInflater mLayoutInflater;

    public ClubListAdapter(Context mContext, List mDataList) {
        this.mContext = mContext;
        this.mDataList = mDataList;
        mLayoutInflater = LayoutInflater.from(mContext);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = mLayoutInflater.from(parent.getContext()).inflate(R.layout.cardview_clublist, parent, false);
        return new ViewHolder(v);

    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final Club entity = (Club) mDataList.get(position);
        if (null == entity)
            return;
        ViewHolder viewHolder = (ViewHolder) holder;
        viewHolder.CL_text.setText(entity.getClub_name());
        Picasso.with(mContext).
                load(Constant.PIC_URL + entity.getThumb()).into(viewHolder.CL_photo);

        /*做一个页面跳转*/
        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(mContext, ClubInfoActivity.class);
                intent.putExtra("club_id", entity.getId());
                intent.putExtra("club_photo", entity.getThumb());
                intent.putExtra("club_name", entity.getClub_name());
                mContext.startActivity(intent);
            }
        });

    }

    @Override
    public int getItemCount() {
        return mDataList.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        ImageView CL_photo;
        TextView CL_text, CL_ID;
        LinearLayout club_container;

        public ViewHolder(View itemView) {
            super(itemView);
            club_container = (LinearLayout) itemView.findViewById(R.id.club_container);
            CL_photo = (ImageView) itemView.findViewById(R.id.CL_photo);
            CL_text = (TextView) itemView.findViewById(R.id.CL_text);
        }
    }

}

